package com.snowyee.yudada.mapper;

import com.snowyee.yudada.model.dto.statistic.AppAnswerCountDTO;
import com.snowyee.yudada.model.dto.statistic.AppAnswerResultCountDTO;
import com.snowyee.yudada.model.entity.UserAnswer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 19457
* @description 针对表【user_answer(用户答题记录)】的数据库操作Mapper
* @createDate 2024-07-04 14:56:11
* @Entity generator.domain.UserAnswer
*/
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {


    /**
     * 记录每个appId下，有多少次回答，一个用户可以有多次回答
     * 可以做热门应用排行榜
     * @return
     */
    @Select("select appId,count(userId) as answerCount from user_answer" +
            "       group by appId order by answerCount desc limit 10;")
    List<AppAnswerCountDTO> doAppAnswerCount();

    /**
     * 记录每个描述结果下，有多少次回答
     * @param appId
     * @return
     */
    @Select("select resultName,count(resultName) as resultCount from user_answer" +
            "   where appId = #{appId}" +
            "   group by resultName order by resultCount desc;")
    List<AppAnswerResultCountDTO> doAppAnswerResultCount(Long appId);
}




